package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.TSalesConsultantCheckModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.util.List;

/**
 * 销售顾问核检持久层
 * Created by wzy on 2017/5/19.
 */
public interface SalesConsultantCheckRepository extends JpaRepository<TSalesConsultantCheckModel, Integer>, JpaSpecificationExecutor<TSalesConsultantCheckModel> {

    /**
     *  根据导入批次和导入用户,查找销售顾问数据
     * @param importBatch 导入批次
     * @param importUser 导入用户
     * @return 返回
     */
    @Query("select u from TSalesConsultantCheckModel u where u.importBatch =?1 and u.importUser = ?2")
    List<TSalesConsultantCheckModel> findSalesConsultantByImportBatchAndImportUser(String importBatch, String importUser);

    /**
     * 根据导入批次和车架号和客户电话,查找销售顾问数据
     * @param importBatch 导入批次
     * @param vin 车架号
     * @param customTel 客户电话
     * @return 返回
     */
    @Query("select u from TSalesConsultantCheckModel u where u.importBatch = ?1 and u.vin = ?2 and u.customTel = ?3")
    List<TSalesConsultantCheckModel> findSalesConsultantByImportBatchAndVinAndCustomTel(String importBatch, String vin, String customTel);

    /**
     * 根据导入批次和客户电话和意向车型和意向金，查找销售顾问数据
     * @param importBatch 导入批次
     * @param customTel 客户电话
     * @param intentCar 意向车型
     * @param ioAmount 意向金
     * @return 返回
     */
    @Query("select  u from TSalesConsultantCheckModel u where u.importBatch = ?1 and u.customTel = ?2 and u.intentCar = ?3 and u.ioAmount = ?4")
    List<TSalesConsultantCheckModel> findSalesConsultantByImportBatchAndCustomTelAndIntentCarAndIoAmount(String importBatch,String customTel,String intentCar,BigDecimal ioAmount);

    /**
     * 根据车架号和客户电话,查找销售顾问数据
     * @param vin 车架号
     * @param customTel 客户电话
     * @return 返回
     */
    @Query("select u from TSalesConsultantCheckModel u where u.vin = ?1 and u.customTel = ?2")
    List<TSalesConsultantCheckModel> findSalesConsultantByVinAndCustomTel(String vin, String customTel);

    /**
     * 根据客户电话和意向车型和意向金，查找销售顾问数据
     * @param customTel 客户电话
     * @param intentCar 意向车型
     * @param ioAmount 意向金
     * @return List<TSalesConsultantCheckModel>
     */
    @Query("select  u from TSalesConsultantCheckModel u where u.customTel = ?1 and u.intentCar = ?2 and u.ioAmount = ?3")
    List<TSalesConsultantCheckModel> findSalesConsultantByCustomTelAndIntentCarAndIoAmount(String customTel,String intentCar,BigDecimal ioAmount);

}
